#ifndef BlueTooth_H
#define BlueTooth_H

#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothSocket>
#include <QIODevice>
#include <QObject>

class QBluetoothLocalDevice;
class QBlueToothUuid;
class QBluetoothAddress;
class QBlueToothDeviceInfo;

class Bluetooth : public QObject
{
    Q_OBJECT

public:
    static const QString serviceUuid;

public:
    explicit Bluetooth(QObject* parent = nullptr);
    ~Bluetooth();

    void restart();
    void stop();
    void connectDevice(const QBluetoothAddress& address, const QBluetoothUuid& uuid, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
    void disconnectDevice();
    bool isConnected() const;
    QByteArray readAll();
    void write(const QByteArray& dat);

signals:
    void deviceDiscovered(const QBluetoothDeviceInfo& info);
    void discoverError(QBluetoothDeviceDiscoveryAgent::Error error);
    void connected();
    void readyRead();
    void socketError(QBluetoothSocket::SocketError error);

private:
    QBluetoothLocalDevice* localDevice; // 对本地设备进行操作，比如进行设备的打开，设备的关闭等等
    QBluetoothDeviceDiscoveryAgent* discoveryAgent; // 用来对周围蓝牙进行搜寻
    QBluetoothSocket* socket; // 负责蓝牙通信
};

#endif // BlueTooth_H
